package com.qrback.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
public class RequestMonitorFilter implements Filter {
    private static final Logger logger = LoggerFactory.getLogger(RequestMonitorFilter.class);

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // 打印hello字符串到控制台
        System.out.println("hello");
        
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        // 打印请求的URL和方法
        logger.info("请求到达：{} {}" ,
                   httpRequest.getMethod(),
                   httpRequest.getRequestURI());
        // 继续处理请求
        chain.doFilter(request, response);
    }
}